home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / ansitc / ansi.c next >
Text File  |  1987-08-20  |  4KB  |  116 lines

  1. /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
  2. /*   ANSI Generator Function - This function will return the ANSI    */
  3. /*   color codes for the foreground and background colors passed as  */
  4. /*   paramaters.  The forground and background colors are in the     */
  5. /*   range of:                                                       */
  6. /*              FOREGROUND             BACKGROUND                    */
  7. /*              0 = black              0 = black                     */
  8. /*              1 = blue               1 = blue                      */
  9. /*              2 = green              2 = green                     */
  10. /*              3 = cyan               3 = cyan                      */
  11. /*              4 = red                4 = red                       */
  12. /*              5 = magenta            5 = magenta                   */
  13. /*              6 = brown              6 = brown                     */
  14. /*              7 = grey               7 = grey                      */
  15. /*              8 = light grey                                       */
  16. /*              9 = light blue                                       */
  17. /*             10 = light green                                      */
  18. /*             11 = light cyan                                       */
  19. /*             12 = light red                                        */
  20. /*             13 = light magenta                                    */
  21. /*             14 = yellow                                           */
  22. /*             15 = white                                            */
  23. /*             16 = blink on                                         */
  24. /*             17 = blink off                                        */
  25.  
  26. void SET_COLOR(int foreground,int background, char string[])
  27. {
  28.     switch(background)
  29.     {
  30.         case 0:
  31.                 strcpy(string,"\x1b[40m");
  32.                 break;
  33.         case 1:
  34.                 strcpy(string,"\x1b[44m");
  35.                 break;
  36.         case 2:
  37.                 strcpy(string,"\x1b[42m");
  38.                 break;
  39.         case 3:
  40.                 strcpy(string,"\x1b[46m");
  41.                 break;
  42.         case 4:
  43.                 strcpy(string,"\x1b[41m");
  44.                 break;
  45.         case 5:
  46.                 strcpy(string,"\x1b[45m");
  47.                 break;
  48.         case 6:
  49.                 strcpy(string,"\x1b[43m");
  50.                 break;
  51.         case 7:
  52.                 strcpy(string,"\x1b[47m");
  53.                 break;
  54.         default:break;
  55.     }
  56.  
  57.     switch(foreground)
  58.     {
  59.         case 0:
  60.                 strcat(string,"\x1b[30m");
  61.                 break;
  62.         case 1:
  63.                 strcat(string,"\x1b[34m");
  64.                 break;
  65.         case 2:
  66.                 strcat(string,"\x1b[32m");
  67.                 break;
  68.         case 3:
  69.                 strcat(string,"\x1b[36m");
  70.                 break;
  71.         case 4:
  72.                 strcat(string,"\x1b[31m");
  73.                 break;
  74.         case 5:
  75.                 strcat(string,"\x1b[35m");
  76.                 break;
  77.         case 6:
  78.                 strcat(string,"\x1b[33m");
  79.                 break;
  80.         case 7:
  81.                 strcat(string,"\x1b[37m");
  82.                 break;
  83.         case 8:
  84.                 strcat(string,"\x1b[1;30m");
  85.                 break;
  86.         case 9:
  87.                 strcat(string,"\x1b[1;34m");
  88.                 break;
  89.         case 10:
  90.                 strcat(string,"\x1b[1;32m");
  91.                 break;
  92.         case 11:
  93.                 strcat(string,"\x1b[1;36m");
  94.                 break;
  95.         case 12:
  96.                 strcat(string,"\x1b[1;31m");
  97.                 break;
  98.         case 13:
  99.                 strcat(string,"\x1b[1;35m");
  100.                 break;
  101.         case 14:
  102.                 strcat(string,"\x1b[1;33m");
  103.                 break;
  104.         case 15:
  105.                 strcat(string,"\x1b[1;37m");
  106.                 break;
  107.         case 16:
  108.                 strcat(string,"\x1b[5");
  109.                 break;
  110.         case 17:
  111.                 strcat(string,"\x1b[0");
  112.                 break;
  113.         default:break;
  114.     }
  115. }
  116.